package edu.zcmu.seckill.rocket.producer;


import edu.zcmu.seckill.exception.MyException;
import edu.zcmu.seckill.response.ResultCode;
import edu.zcmu.seckill.rocket.to.OrderTo;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.apache.rocketmq.spring.support.RocketMQHeaders;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import java.nio.charset.StandardCharsets;

@Slf4j
@Controller
public class OrderProducer {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    public void sendMessage(OrderTo orderTo){
        System.out.println("进入");

        rocketMQTemplate.asyncSend("Order", orderTo, new SendCallback() {
            @Override
            public void onSuccess(SendResult sendResult) {
                log.info("订单消息发送成功");
            }

            @Override
            public void onException(Throwable throwable) {
                log.info("订单消息发送失败");
            }
        });

    }
}
